package com.example.mymicaihu.adapter.network;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.mvplibrary.adapter.BaseAdapter;
import com.example.mvplibrary.adapter.BaseViewHolder;
import com.example.mymicaihu.R;
import com.example.mymicaihu.bean.network.WorkBean;

import java.util.ArrayList;
import java.util.List;


/**
 * 作者：朱勇闯
 * data : 2021/4/25  17:02
 * 作用： xxxx
 */
public class WorkAdapter extends BaseAdapter<WorkBean.CmtListBeanX> {
    private static final String TAG = "朱勇闯WorkAdapter";
    public ItemListener itemListener;

    public void setItemListener(ItemListener itemListener) {
        this.itemListener = itemListener;
    }

    public WorkAdapter(List<WorkBean.CmtListBeanX> datas, Context context, int layoutId) {
        super(datas, context, layoutId);
    }

    @Override
    protected void bindData(BaseViewHolder holder, WorkBean.CmtListBeanX listBean, int position) {
        TextView nickName = holder.getView(R.id.tv_item_network_work_nickName);
        TextView content = holder.getView(R.id.tv_item_network_work_content);
        TextView title = holder.getView(R.id.tv_item_network_work_title);
        TextView armyGroupInfo = holder.getView(R.id.tv_item_network_work_armyGroupInfo);
        TextView publishTime = holder.getView(R.id.tv_item_network_work_publishTime);
        TextView rankName = holder.getView(R.id.tv_item_network_work_rankName);
        TextView load = holder.getView(R.id.tv_item_network_work_load);

        ImageView head = holder.getView(R.id.iv_item_network_work_head);
        ImageView honourPic = holder.getView(R.id.iv_item_network_work_honourPic);
        ImageView rankIcon = holder.getView(R.id.iv_item_network_work_rankIcon);
        if (listBean.getImgList() != null) {
            for (int i = 0; i < listBean.getImgList().size(); i++) {
                if (listBean.getImgList().size() < 3) {
                    List<String> newImgList = new ArrayList<>();
                    newImgList.add(listBean.getImgList().get(i));
                    RecyclerView image = holder.getView(R.id.rv_network_work_image);
                    LinearLayoutManager manager = new LinearLayoutManager(context);
                    manager.setOrientation(LinearLayoutManager.HORIZONTAL);
                    image.setLayoutManager(manager);
                    WorkImageAdapter workImageAdapter = new WorkImageAdapter(newImgList, context, R.layout.item_work_image);
                    image.setAdapter(workImageAdapter);
                }
            }
        }


        nickName.setText(listBean.getNickName());
        content.setText(listBean.getContent());
        armyGroupInfo.setText(listBean.getArmyGroupInfo());
        publishTime.setText(listBean.getPublishTime());
        rankName.setText(listBean.getRankName());
        if (listBean.getTitle().equals("") || listBean.getTitle() == null) {
            title.setVisibility(View.GONE);
        } else {
            title.setText(listBean.getTitle());
        }
        if (content.length() < 100) {
            load.setVisibility(View.GONE);
        } else if (content.length() > 100) {
            load.setVisibility(View.VISIBLE);
        }

        Glide.with(context).load(listBean.getHeadPic()).into(head);
        Glide.with(context).load(listBean.getHonourPic()).into(honourPic);
        Glide.with(context).load(listBean.getRankIcon()).into(rankIcon);
    }

    public interface ItemListener {
        void onItemClickListener(int pos);
    }

}
